package com.asa.tongji.fenxi;

import com.asa.hutils.MathHUtils;
import com.asa.hutils.teizheng.Eigenvalue;
import com.asa.hutils.teizheng.structure.Matrix;
import com.asa.tongji.TUtils1;
import com.asa.utils.Calculate;

/**
 * 主成分分析
 * @author Administrator
 *功能已经做完了，但是还没有封装，灵活化，都是写死了的
 */
public class ChengFenFenXiTest {

	static double a[] = {2,1,5,2,3,4,4,1,3,5};
	static double b[] = {4,5,3,2,5,3,4,2,3,5};
	static double c[] = {5,1,4,3,5,2,3,1,2,3};
	public static void main(String[] args) throws Exception {
		
		double averagea = TUtils1.average(a);
		double averageb = TUtils1.average(b);
		double averagec = TUtils1.average(c);
		
		//System.out.println(averagea+"\t"+averageb+"\t"+averagec);
		double variancea = TUtils1.standardDeviation(a);
		double varianceb = TUtils1.standardDeviation(b);
		double variancec = TUtils1.standardDeviation(c);
		//System.out.println(variancea+"\t"+varianceb+"\t"+variancec);
		
		
		double au[] = new double[a.length];
		double bu[] = new double[b.length];
		double cu[] = new double[c.length];
		
		
		for (int i = 0; i < au.length; i++) {
			au[i] = (a[i]-averagea)/variancea;
		}
		for (int i = 0; i < bu.length; i++) {
			bu[i] = (b[i]-averageb)/varianceb;
		}
		for (int i = 0; i < cu.length; i++) {
			cu[i] = (c[i]-averagec)/variancec;
		}
		//System.out.println("===============================");
		for (int i = 0; i < cu.length; i++) {
			//System.out.println(au[i]+"\t"+bu[i]+"\t"+cu[i]);
		}
		                                       
		
		double[][] data = {{1,0.19,0.36},{0.19,1,0.30},{0.36,0.3,1}};
		
		double[] juzhengtezhengzhi = MathHUtils.juzhengtezhengzhi(data);
		double[][] data2 = {{4,6,9},{5,2,5},{2,3,7}};
		double[][] juzhengtezhengxiangliang = MathHUtils.juzhengtezhengxiangliang(data);
		//System.out.println("===============================");
		//System.out.println(juzhengtezhengzhi[0]+"\t"+juzhengtezhengzhi[1]+"\t"+juzhengtezhengzhi[2]);
		
		for (int i = 0; i < juzhengtezhengxiangliang.length; i++) {
			for (int j = 0; j < juzhengtezhengxiangliang.length; j++) {
				System.out.print(juzhengtezhengxiangliang[i][j]+"\t");
			}
			//System.out.println();
		}
		
		//System.out.println("*********************************");
		
		double asa[][] = new double[au.length][3];
		for (int i = 0; i < asa.length; i++) {
			asa[i][0] = au[i];
			asa[i][1] = bu[i];
			asa[i][2] = cu[i];
		}
		
		for (int i = 0; i < asa.length; i++) {
			//System.out.println(func(asa[i],juzhengtezhengxiangliang[0]));
		}
		//System.out.println("...............................");
		for (int i = 0; i < asa.length; i++) {
			//System.out.println(func(asa[i],juzhengtezhengxiangliang[1]));
		}
		
		
	}
	
	
	private static double func(double[] a,double[] u){
		double sum = 0;
		for (int i = 0; i < u.length; i++) {
			sum += a[i]*u[i];
		}
		return sum;
	}
	
	
	
	
	
	
	
	
	
}
